package esdemo;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.junit.Test;

public class TransportClientTest {
	@Test
	public void test01() throws UnknownHostException{
		//获取客户端
		TransportClient client = TransportClient.builder().build()
		.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
//        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
	
		client.close();
	}
	
	/**
	 * Note that you have to set the cluster name if you use one different than "elasticsearch":
	 */
	@Test
	@SuppressWarnings("unused")
	public void test02() throws UnknownHostException{
		Settings settings = Settings.settingsBuilder()
		        .put("cluster.name", "myClusterName").build();
		Client client = TransportClient.builder().settings(settings).build();
		//Add transport addresses and do something with the client...
	}
}
